#include<bits/stdc++.h>
using namespace std;

int a[200010];
unordered_map<int, int> mp;

int main()
{
	int n, c;
//	freopen("D:\\desktop\\P1102_3.in", "r", stdin);
	cin>>n>>c;
	for(int i = 1;i <= n;i++)
	{
		cin>>a[i];
		if(mp.count(a[i]) == 0)
			mp[a[i]] = 1;
		else
			mp[a[i]]++;
	}
	
	long long ans = 0;
	sort(a+1, a+n+1);
	for(int i = 1;i < n;i++)
	{
//		if(a[i] == a[i-1])
//			continue;
		int target = a[i]+c;
		if(mp.count(target))
			ans += mp[target];
	}
	cout<<ans;
	return 0;
}

